

#ifndef __CE_EFFECT_H__
#define __CE_EFFECT_H__

#include <cegfx/ce.h>
#include <cegfx/ceexport.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <cecore/iqf.h>

class CE_GFX_API ceEffect : public iBase
{
	IQF_DECLARATION;
private:
	LPD3DXEFFECT	effect;

	D3DXHANDLE		handleProjMat;
	D3DXHANDLE		handleViewMat;
	D3DXHANDLE		handleWorldMat;

	D3DXHANDLE		handleMatAmbient;
	D3DXHANDLE		handleMatDiffuse;
	D3DXHANDLE		handleMatSpecular;
	D3DXHANDLE		handleMatEmissive;
	D3DXHANDLE		handleMatPower;

	D3DXHANDLE		handleLightAmbient;
	D3DXHANDLE		handleLightDiffuse;
	D3DXHANDLE		handleLightSpecular;
	D3DXHANDLE		handleLightPosition;
	D3DXHANDLE		handleLightDirection;
	D3DXHANDLE		handleLightRange;

	D3DXHANDLE		handleTextureDiffuse;
	D3DXHANDLE		handleTextureSpecular;
	D3DXHANDLE		handleTextureBump;

	D3DXHANDLE		handleTextureEffect0;

	static ceEffect*	currentEffect;
public:
	ceEffect ();
	~ceEffect ();

	void SetEffect (LPD3DXEFFECT effect);
	LPD3DXEFFECT GetEffect ();

	void SetProjMatrix (const D3DXMATRIX& proj);
	void SetViewMatrix (const D3DXMATRIX& view);
	void SetWorldMatrix (const D3DXMATRIX& world);
	void SetMatrices (const D3DXMATRIX& proj, const D3DXMATRIX& view, const D3DXMATRIX& world);

	void SetMaterial (const D3DMATERIAL9& mat);
	void SetLight (const D3DLIGHT9& light);
	void SetDiffuseTexture (LPDIRECT3DTEXTURE9 diffuse);
	void SetSpecularTexture (LPDIRECT3DTEXTURE9 diffuse);
	void SetBumpTexture (LPDIRECT3DTEXTURE9 diffuse);
	void SetEffect0Texture (LPDIRECT3DTEXTURE9 texture);

	D3DXHANDLE GetHandleByName (const char* handleName);
	D3DXHANDLE GetHandleBySemantic (const char* handleSemantic);
	void SetVector (D3DXHANDLE handle, const D3DXVECTOR4* vec);
	void SetVertices (D3DXHANDLE handle, unsigned num, const D3DXVECTOR4* vec);
	void SetMatrix (D3DXHANDLE handle, const D3DXMATRIX* matrix);
	void SetMatrices (D3DXHANDLE handle, unsigned num, const D3DXMATRIX* matrix);

	unsigned Begin ();
	void BeginPass (unsigned pass);
	void EndPass ();
	void End ();

	static ceEffect* GetCurrentEffect ();
};


#endif /* ! __CE_EFFECT_H__ */ 
